package cn.bdqn.util;

import java.io.IOException;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class UserUtil {

	private static SqlSessionFactory ssf;

	static {//放在静态代码块下，SqlSessionFactory只会被创建一次；
		try {
			ssf = new SqlSessionFactoryBuilder().build(Resources
					.getResourceAsStream("Mybatis-config.xml"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static SqlSession getSQLsession() {
		return ssf.openSession();
	}
	
	public static void closeSQLsession(SqlSession sqlsession){
		if(sqlsession!=null){
			sqlsession.close();
		}
		
	}
	

}
